package com.ss.android.topic.e.a;

import com.bytedance.retrofit2.Call;
import com.bytedance.retrofit2.Callback;
import com.bytedance.retrofit2.ResponseWrapper;
import com.bytedance.retrofit2.mime.FormUrlEncodedTypedOutput;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Map;

public abstract class a implements Call {
    private String a;
    private Call b;
    private Callback c;

    public a(String arg2, Map arg3, Callback arg4) {
        this.a = arg2;
        this.b = this.a(arg2, arg3);
        this.c = this.b(arg4);
    }

    public abstract Call a(String arg1, Map arg2);

    public static FormUrlEncodedTypedOutput a(Map arg4) {
        FormUrlEncodedTypedOutput v2 = new FormUrlEncodedTypedOutput();
        if(arg4 != null) {
            Iterator<Entry> v3 = arg4.entrySet().iterator();
            while(v3.hasNext()) {
                Entry v0 = v3.next();
                v2.addField((String) v0.getKey(), (String) v0.getValue());
            }
        }

        return v2;
    }

    public final ResponseWrapper execute() throws IOException {
        ResponseWrapper v0;
        if(this.b != null) {
            v0 = this.b.execute();
            v0 = ResponseWrapper.createResponseWrapper(this.a(v0.body), v0.rawResponse);
        }
        else {
            v0 = null;
        }

        return v0;
    }

    public abstract Object a(Object arg1);

    public final void enqueue(Callback callback) {
        if(this.b != null) {
            this.b.enqueue(this.b(callback));
        }
    }

    private Callback b(Callback arg2) {
        return new com.ss.android.topic.e.a.b(this, arg2);
    }

    public final void cancel() {
        if(this.b != null) {
            this.b.cancel();
        }
    }

    public final boolean isCanceled() {
        boolean v0 = this.b != null ? this.b.isCanceled() : true;
        return v0;
    }

    public Call clone() throws CloneNotSupportedException {
        return new c(this.a);
    }

    public final void e() {
        if(this.b != null) {
            this.b.enqueue(this.c);
        }
    }
}

